package com.example.servletdemo.servlet.listner.session;

import com.example.servletdemo.listner.session.UserSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/UserSessionActivationGetServlet")
public class UserSessionActivationGetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //HttpSession属性的设置
        HttpSession session = req.getSession();

        resp.setContentType("text/html;charset=utf-8");
        UserSession user = (UserSession) session.getAttribute("user");
        resp.getWriter().write("User session =>"+user.getUsername()+":"+user.getPassword());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
